package com.artPreter.controller;


import com.artPreter.pojo.Article;
import com.artPreter.pojo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.artPreter.service.IArticleService;
import com.artPreter.service.IArtistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文章内容表 前端控制器
 * </p>
 *
 * @author jarvis
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private IArticleService articleService;

    /**
     * 添加文章
     * @param article
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Article article){
        articleService.add(article);
        return Result.success();
    }

    /**
     * 编辑文章
     * @param article
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody Article article){
        articleService.edit(article);
        return Result.success();
    }

    /**
     * 删除文章
     * @param article
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Article article){
        articleService.delete(article);
        return Result.success();
    }

    /**
     * 文章分页
     * @param currentPage
     * @param size
     * @param
     * @return
     */
    @PostMapping("/getPage")
    public Result getPage(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Article article){
        IPage<Article> articleIPage = articleService.getPage(currentPage,size,article);
        return Result.success(articleIPage);
    }

    /**
     * 添加到文章关联表
     * @param
     * @return
     */
    @PostMapping("/addToRelative")
    public Result addToRelative(@RequestBody Article article){
        articleService.addToRelative(article);
        return Result.success();
    }

    /**
     * 删除关联文章
     * @param
     * @return
     */
    @PostMapping("/removeArticleRelative")
    public Result removeArticleRelative(@RequestBody Article article){
        articleService.removeArticleRelative(article);
        return Result.success();
    }

    /**
     * 围观关联文章分页
     * @param currentPage
     * @param size
     * @param
     * @return
     */
    @PostMapping("/getPageNoRelative")
    public Result getPageNoRelative(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Article article){
        IPage<Article> articleIPage = articleService.getPageNoRelative(currentPage,size,article);
        return Result.success(articleIPage);
    }

    /**
     * 已关联文章分页
     * @param currentPage
     * @param size
     * @param
     * @return
     */
    @PostMapping("/getPageRelative")
    public Result getPageRelative(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Article article){
        IPage<Article> articleIPage = articleService.getPageRelative(currentPage,size,article);
        return Result.success(articleIPage);
    }

    /**
     * 宣和艺网板块已关联文章分页
     * @param currentPage
     * @param size
     * @param
     * @return
     */
    @PostMapping("/getPageRelativeFull")
    public Result getPageRelativeFull(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Article article){
        IPage<Article> articleIPage = articleService.getPageRelativeFull(currentPage,size,article);
        return Result.success(articleIPage);
    }

    /**
     * 宣和艺网板块未关联文章分页
     * @param currentPage
     * @param size
     * @param
     * @return
     */
    @PostMapping("/getPageNoRelativeFull")
    public Result getPageNoRelativeFull(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Article article){
        IPage<Article> articleIPage = articleService.getPageNoRelativeFull(currentPage,size,article);
        return Result.success(articleIPage);
    }



    @PostMapping("/saveSortInArticleRelative")
    public Result saveSortInArticleRelative(@RequestBody List<Article> articleList){
        articleService.saveSortInArticleRelative(articleList);
        return Result.success();
    }



}
